<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<?php 
include('getsubcat.php');
$zone = $_POST['zone'];
$city = $_POST['city'];
$Category = $_POST['Category'];
$subcat = $_POST['subcat'];
$jobnature = $_POST['jobnature'];
$desc = mysql_real_escape_string($_POST['maincont']);
$worktype = $_POST['worktype'];
$sal = $_POST['sal'];
$date = $_POST['date'];
$worktype = $_POST['worktype'];
$file1 = $_POST['loadfile'];
$authorised = $_POST['authorised'];


if(isset($_POST['savejob']))
{
	
     $file="../uploads/pages/".gmdate('YmdHis').$_FILES["loadfile"]["name"] ;
     move_uploaded_file($_FILES["loadfile"]["tmp_name"],$file);
	
	if($_GET['m']!=edit)
	{							
		mysql_query("INSERT INTO job_post (`zone_id`, `city_id`, `cat_id`, `sub_cat_id`, `job_nature`, `job_desc`, `work_type`, `salary`, `post_date`, `File`, `active_status`, `created_datetime`)
												  VALUES ('$zone','$city','$Category','$subcat'														                                                          ,'$jobnature','$desc','$worktype','$sal','$date','$file',
														  '$authorised','".gmdate('Y-m-d H:i:s')."')");	
		//header("location: index.php?tc=addcat&_s=1");
		
		echo "<script>window.location='index.php?tc=add_job_post&_s=1'</script>";
	}
	
}
if(isset($_POST['updatejob']))

{
	
	$q = mysql_fetch_array(mysql_query("select File  from job_post where id='".$_POST['hid']."'"));
	
	if($_FILES["loadfile"]["name"]=="")
	{
		 $file=$q['File'];	
	
	}
	if($_FILES["loadfile"]["name"]!="")
	{
	
	$path = "../pages/".$q["File"];
	@unlink($path);
	$file="../uploads/pages/".gmdate('YmdHis').$_FILES["loadfile"]["name"] ;
	move_uploaded_file($_FILES["loadfile"]["tmp_name"],$file);
	}
	
mysql_query("UPDATE job_post  SET `zone_id` ='$zone', `city_id`='$city',`cat_id`='$Category',`sub_cat_id`='$subcat',`job_nature`='$jobnature',
			
			`job_desc` ='$desc',`work_type`='$worktype',`salary`='$sal',`post_date`='$date',`File`='".$file."',`active_status` ='$authorised',`modified_datetime`='".gmdate('Y-m-d H:i:s')."' where id='".$_POST['hid']."'")
or 
die(mysql_error());

	
	echo "<script>window.location='index.php?tc=job_post&_s=1'</script>";
	
}

?><head>

<script type="text/javascript">
function state(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {

    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
	//alert(xmlhttp.responseText);
    }
  }
  
xmlhttp.open("GET","getcity.php?q="+str,true);
xmlhttp.send();
}

function cat(str)
{
	
if (str=="")
  {
	 
  document.getElementById("txtHint1").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {

    document.getElementById("txtHint1").innerHTML=xmlhttp.responseText;
    }
  }
  
xmlhttp.open("GET","getsubcat.php?q="+str,true);
xmlhttp.send();
}
</script>
<script type="text/javascript">
function validate()
{
	
	if(document.up.jobnature.value=="")
	{
		alert("Job Nature Missing.");	
		document.up.jobnature.focus();
		return false;
	}
	var no=/^[0-9.]+$/;
		if(!no.test(document.up.sal.value))
		alert("Job Salary Missing.");	
		document.up.sal.focus();
		return false;
	}
}
</script>
</head>
<?php if($_REQUEST['_s'] == 1){ ?>
    
<div class="sucmsg"><img src="images/information.png" align="absmiddle" />&nbsp;Successfully saved.</div>
<?php } ?>
<?php if($_REQUEST['_e'] == 1){ ?>
    <div class="sucmsg"><img src="images/error.png" align="absmiddle" />&nbsp;</div>
<?php } ?>
<?php 
$ssql="select * from job_post where id='".$_GET['_d']. "'";
$ssql=mysql_query($ssql);
$row =mysql_fetch_array($ssql);

if($row['active_status']=='1')
{
$chkact = 'checked="checked"';
}
if($row['active_status']=='0')
{
$chkdec = 'checked="checked"';
}
?>
<form name="up" action="#" method="post"  enctype="multipart/form-data" onsubmit="return validate();">
<table width="99%" align="center" border="0"  class="list" cellpadding="5">
<input type="hidden" name="hid" value="<?php echo  $row['id'];?>" />
<thead>

<tr>
	<td colspan="2" align="left">
        <div style="float:left" class="righthead">Post jobs</div>
        <div style="float:right"><a href="index.php?tc=job_post" class="back">View Jobs</a></div>
    </td>
</tr>
</thead>
<tr>
	<td align="right" width="150">Zone</td>
    <td align="left">
<select name="zone" id="zone" class="txtborder" style="width:220px;" onchange="return state(this.value)"  >
    <option value="">Select Zone </option> 
	<?php 
	
	
$ads=mysql_query("select * from zone where active_status='1' order by id ASC");
while($tech=mysql_fetch_array($ads)){
	
	?>

    <option <?php if($row['zone_id']==$tech['id']){echo "selected";}?> value="<?php echo $tech['id']?>">
	<?php echo $tech['zone_name']?></option>
    <?php }?>
    </select></td></tr>
<tr>
	<td align="right" width="150">City</td>
    <td align="left">
   <div id="txtHint">
   <select name="city"  style="width:220px;"  >
<?php 
	
 $ads=mysql_query("select * from city where zone_id='".$row['zone_id']."' and active_status='1' order by city_id ASC");
while($tech=mysql_fetch_array($ads)){
	
	?>
      <option <?php if($row['city_id']==$tech['city_id']){echo "selected";}?>  value="<?php echo  $tech['city_id'];?>">
        <?php //echo $str;?>
         <?php echo $tech['city_name'];?>
         </option> 
         <?php } ?>
   </select>
   </div>
</td></tr>
<tr>
		
	<td align="right" width="150">Category</td>
    <td align="left">
<select name="Category" id="Category" class="txtborder" style="width:220px;" onchange="return cat(this.value)"> 
    <option value="">Select Category</option>
	<?php  
$ads=mysql_query("select * from job_category where active_status='1' order by id ASC");
while($tech=mysql_fetch_array($ads)){
	?>
    <option <?php if($row['cat_id']==$tech['id']){echo "selected";}?> value="<?php echo $tech['id']?>">
	<?php echo $tech['category']?></option>
    <?php }?>
    </select></td></tr>
    <tr>
	<td align="right" width="150">Sub Category</td>
    <td align="left">
	<div id="txtHint1">
	<select name="subcat"  style="width:220px;"> 
   <?php 
	
 $ads=mysql_query("select * from job_subcategory where 	id='".$row['sub_cat_id']."' and active_status='1' order by id ASC");
while($tech=mysql_fetch_array($ads)){
	
	?> 

  
      <option  <?php if($row['sub_cat_id']==$tech['id']){echo "selected";}?> value="<?php echo $tech['id']?>">
          <?php echo $tech['sub_cat_name'];?>
         </option>  <?php }?>
   </select>
   </div>
</td></tr>    
<tr>
	<td align="right" width="150">Job Nature *</td>
    <td align="left"><input type="text" name="jobnature" style="width:200px;" value="<?php echo  $row['job_nature'];?>"  /></td>
</tr>
<tr>
	<td align="right" width="250">Job Description</td>
    <td align="left">
     <textarea name="maincont" id="maincont" class="textarea" cols="25" rows="5"><?php echo  stripslashes($row['job_desc']);?></textarea>
     <script type="text/javascript">CKEDITOR.replace( 'maincont',{skin : 'kama'});</script>
     
   </td>
</tr>
<tr>
  <td align="right" width="150">Work Type </td>
  <td align="left">
  <select name="worktype" id="worktype" class="txtborder" style="width:220px;">
  <option value="Full Time">Full Time</option>
   <option value="Part Time">Part Time</option>
		<script language="javascript">
            document.up.worktype.value="<?php echo  $row['work_type'];?>";
        </script>
    </select>
  </td>
</tr>
<tr>
	<td align="right" width="250">Salary *</td>
    <td align="left"><input type="text" name="sal" style="width:200px;" value="<?php echo  $row['salary'];?>"  /></td>
</tr>
<tr>
	<td align="right" width="250">Last Date *</td>
    <td align="left"><input type="text" name="date" style="width:200px;" value="<?php echo  $row['post_date'];?>"  /></td>
</tr>
<tr>
	<td align="right" width="250">File</td>
    <td align="left"><input type="file" name="loadfile" style="width:200px;" value="<?php echo $row["File"];?>"  />&nbsp;&nbsp;&nbsp;&nbsp;
   <?php if($row["File"]!="")
   {?>
   <a href="../pages/<?php echo $row["File"];?>"><img src="../images/html_ico.png" border="0" /></a><?php } ?></td>
</tr>
<tr>
  <td align="right" width="150">Status :</td>
  <td align="left">
  <input name="authorised" type="radio" checked="checked"  value="1" <?php echo $chkact;?> />&nbsp;Active&nbsp;&nbsp;
  <input  name="authorised" type="radio" value="0" <?php echo $chkdec;?> />&nbsp;Deactive</td>
</tr>

<tr>
	<td colspan="2" style="padding-left:250px;">
    	<?php if($_GET['m']!=edit){?>
        <input type="submit" value="Save" name="savejob" >&nbsp;&nbsp;
        <?php }
        else
		{
         ?>
          <input type="submit" value="Update" name="updatejob" >
         <?php 
		
		}
         ?>
    </td>
</tr>        
</table>   
</form> 
